package cn.iocoder.yudao.module.bpm.service.feign;

import cn.iocoder.yudao.module.bpm.api.task.dto.ApiBpmProcessInstanceCreateReqKeyVO;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqVO;
import cn.iocoder.yudao.module.bpm.feign.BpmWfFlowApi;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import com.xueyi.common.core.exception.ServiceException;
import com.xueyi.common.core.pojo.CommonResult;
import com.xueyi.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BpmWfFlowApiImpl implements BpmWfFlowApi {

    @Autowired
    private BpmProcessInstanceService bpmProcessInstanceService;

    @Override
    public CommonResult<Object> createProcessInstance(ApiBpmProcessInstanceCreateReqKeyVO reqVO) {
        try{
            String definitionkey = reqVO.getDefinitionkey();
            if(StringUtils.isEmpty(definitionkey)){
                throw new ServiceException("流程定义key不能为空!");
            }
            String processInstanceId = bpmProcessInstanceService.createProcessInstance(reqVO);
            return CommonResult.success(processInstanceId);
        }catch (ServiceException e){
            e.printStackTrace();
            return CommonResult.error(e);
        }
    }


}
